<?php

/**
 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
 *
 * To override detran_widgets_init() in a child theme, remove the action hook and add your own
 * function tied to the init hook.
 *
 * @since Twenty Ten 1.0
 * @uses register_sidebar
 */
 
if  (function_exists('add_theme_support')){ 
    add_theme_support('post-thumbnails' );
    //add_image_size('medium', 265, 190,true);
//    add_image_size('noticia', 120, 80,true);  
    add_theme_support('nav-menus');
    add_theme_support('automatic-feed-links');
    //add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
    //add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link','status', 'video', 'audio','chat','quote' ) );
    add_post_type_support( 'page', 'post-formats' );
}

//registrando widgets 
function ronaldoneiva_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Slider', 'ronaldoneiva' ),
        'id' => 'slider',
        'class' => 'item',
        'description' => __( 'Slider', 'ronaldoneiva' ),
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
    ));
    register_sidebar( array(
        'name' => __( 'Barra Lateral', 'ronaldoneiva' ),
        'id' => 'sidebar',
        'class' => '',
        'description' => __( 'Barra Lateral', 'ronaldoneiva' ),
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h1 class="titulo">',
		'after_title' => '</h1>',        
    ));
    register_sidebar( array(
        'name' => __( 'Rodapé 1', 'ronaldoneiva' ),
        'id' => 'rodape-1',
        'class' => '',
        'description' => __( 'Rodapé 1', 'ronaldoneiva' ),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h2>',
		'after_title' => '</h2><hr/>',
    ));
    register_sidebar( array(
        'name' => __( 'Rodapé 2', 'ronaldoneiva' ),
        'id' => 'rodape-2',
        'class' => '',
        'description' => __( 'Rodapé 2', 'ronaldoneiva' ),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h2>',
		'after_title' => '</h2><hr/>',
    ));
    register_sidebar( array(
        'name' => __( 'Rodapé 3', 'ronaldoneiva' ),
        'id' => 'rodape-3',
        'class' => '',
        'description' => __( 'Rodapé 3', 'ronaldoneiva' ),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h2>',
		'after_title' => '</h2><hr/>',
    ));
    
}

//registrando menus
function register_my_menus() {
    register_nav_menus(
        array(
            'menu-principal' => __( 'Menu Principal' )
        )
    );
}
//Codex
function my_function_admin_bar(){
    return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
add_action('init', 'register_my_menus');
add_action('widgets_init', 'ronaldoneiva_widgets_init');


function override_jquery() {
    if( !is_admin()){
        wp_enqueue_script("jquery");
        wp_deregister_script('jquery');
    }
}

/**
 * WP_HEAD
 * itens da <head> do site
 */
function header_append() { ?>
    <!-- CSS -->
    <link rel="stylesheet" media="screen" href="<?php echo get_stylesheet_directory_uri();?>/webroot/css/normalize.css"/>
    <link rel="stylesheet" media="screen" href="<?php echo get_stylesheet_directory_uri();?>/webroot/css/bootstrap.min.css"/>
    <link rel="stylesheet" media="screen" href="<?php echo get_stylesheet_directory_uri();?>/webroot/font-awesome/css/font-awesome.min.css"/>
    <link rel="stylesheet" media="screen" href="<?php echo get_stylesheet_directory_uri();?>/webroot/css/animate-custom.css"/>    
    <!--[if IE 7]>
      <link rel="stylesheet" media="screen" href="<?php echo get_stylesheet_directory_uri();?>/webroot/font-awesome/css/font-awesome-ie7.min.css">
    <![endif]-->            
    <link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" media="screen"/>
    
    <!-- META -->
    <meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset');?>" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
	<meta name="author" content="<?php bloginfo('author'); ?>" />

    <!-- Links: RSS -->
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
    <link rel="shortcut icon" type="image/x-icon" href="<?php echo get_stylesheet_directory_uri();?>/webroot/img/icon.ico"/>
    
    <!-- SEO -->
    <?php if (is_single() or is_home() or is_page()) { ?>
        <meta name="robots" content="index,follow" />
    <?php } ?>
    <?php if ( is_search() or is_month() or is_404() or is_category() or is_tag()) { ?>
        <meta name="robots" content="noindex,nofollow" />
    <?php } ?>
    
    <!-- TITLE -->
	<title>
        <?php if ( is_front_page()) { ?><? bloginfo('name'); ?> | <?php bloginfo('description'); ?><?php } ?>
        <?php if ( is_single() )    { ?><? bloginfo('name'); ?> | <?php wp_title(''); ?><?php } ?>
        <?php if ( is_search() )    { ?><? bloginfo('name'); ?> | <?php echo $s; ?><?php } ?>
        <?php if ( is_page() )      { ?><? bloginfo('name'); ?> | <?php wp_title(''); ?><?php } ?>
        <?php if ( is_category() )  { ?><? bloginfo('name'); ?> | <?php single_cat_title(); ?><?php } ?>
        <?php if ( is_month() )     { ?><? bloginfo('name'); ?> | <?php the_time('F'); ?><?php } ?>
        <?php if ( is_tag() )       { ?><? bloginfo('name'); ?> | <?php single_tag_title();?><?php } ?>
        <?php if ( is_author() )    { ?><? bloginfo('name'); ?> | <?php wp_title(); ?><?php } ?>        
        <?php if ( is_404() )       { ?><? bloginfo('name'); ?> | Desculpe, não encontrado<?php } ?>
    </title>  
<?php
}
add_action( "wp_head", "header_append",0 );


/**
 * WP_FOOTER
 * itens JS antes do fechamento da </body> do site
 */
function footer_append() { ?>    
    <!-- JS -->
    <script src="<?php bloginfo('template_directory');?>/webroot/js/jquery.js"></script>
    <script src="<?php bloginfo('template_directory');?>/webroot/js/bootstrap.min.js"></script>
    <script src="<?php bloginfo('template_directory');?>/webroot/js/modernizr.custom.16608.js"></script>
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <!-- /JS -->
<?php
}
add_action( "wp_footer", "footer_append",0);

//function replace_jquery() {
//    if (!is_admin()) {
//        wp_deregister_script('jquery');
//        wp_register_script('jquery', bloginfo('get_stylesheet_directory_uri').'/webroot/js/jquery.js');
//        wp_enqueue_script('jquery');
//    }
//}
//add_action('init', 'replace_jquery');



require_once('classes/wp_bootstrap_navwalker.php');

// Custom WordPress Login Logo
function my_login_logo() { ?>
    <style type="text/css">
        body.login div#login h1 a {
            background-image: url(<?php bloginfo('template_directory');?>/webroot/img/logo-1.png);
            padding-bottom: 60px;        
        }
        .login h1 a {background-size: auto 120px;}
    </style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );

function my_login_logo_url() {
    return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'my_login_logo_url' );
 
function my_login_logo_url_title() {
    return 'Imobiliária ronaldoneiva';
}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );

function remove_footer_admin () {
	echo '© <a href="http://www.designa3.com.br/" target="blank">Design A3</a> - Desenvolvimento inteligente com padrões web e design';
}
add_filter('admin_footer_text', 'remove_footer_admin');

//Custom dashboard logo
add_filter('admin_head', 'my_custom_logo');
function my_custom_logo() {?>
    <style type="text/css">
        #wp-admin-bar-wp-logo .ab-icon {background: url(<?php bloginfo('template_directory');?>/webroot/img/logo-admin-inner-vermelha.png) no-repeat center top !important; }
    </style>    
<?
}

//PAGINAÇÃO
function page_navi($before = '', $after = '') {
	global $wpdb, $wp_query;
	$request = $wp_query->request;
	$posts_per_page = intval(get_query_var('posts_per_page'));
	$paged = intval(get_query_var('paged'));
	$numposts = $wp_query->found_posts;
	$max_page = $wp_query->max_num_pages;
	if ( $numposts <= $posts_per_page ) { return; }
	if(empty($paged) || $paged == 0) {
		$paged = 1;
	}
	$pages_to_show = 7;
	$pages_to_show_minus_1 = $pages_to_show-1;
	$half_page_start = floor($pages_to_show_minus_1/2);
	$half_page_end = ceil($pages_to_show_minus_1/2);
	$start_page = $paged - $half_page_start;
	if($start_page <= 0) {
		$start_page = 1;
	}
	$end_page = $paged + $half_page_end;
	if(($end_page - $start_page) != $pages_to_show_minus_1) {
		$end_page = $start_page + $pages_to_show_minus_1;
	}
	if($end_page > $max_page) {
		$start_page = $max_page - $pages_to_show_minus_1;
		$end_page = $max_page;
	}
	if($start_page <= 0) {
		$start_page = 1;
	}
		
	echo $before.'<ul class="pagination">';
	if ($paged > 1)
	   echo '<li><a href="'.get_pagenum_link().'" title="Primeira">«</a></li>';
	else
	   echo '<li class="disabled"><a href="'.get_pagenum_link().'" title="Primeira"><i class="icon-double-angle-left"></i></a></li>';
		
	if($prevposts)
        echo '<li>'. get_previous_posts_link('<i class="icon-angle-left"></i>').'</li>';
	else 
        echo '<li class="disabled"><a href="#"><i class="icon-angle-left"></i></a></li>';
	
	for($i = $start_page; $i  <= $end_page; $i++) {
		if($i == $paged) {
			echo '<li class="active"><a href="#">'.$i.'</a></li>';
		} else {
			echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
		}
	}
        
	//TODO: pesquisar teste nextpost
    if ($paged < $max_page)
        echo '<li>'.next_posts_link('<i class="icon-angle-right"></i>').'</li>';
    else
        echo '<li class="disabled">'.next_posts_link('<i class="icon-angle-right"></i>').'</li>';
    
    
    if ($end_page <= $max_page)
		echo '<li class="disabled"><a href="'.get_pagenum_link($max_page).'" title="Último"><i class="icon-double-angle-right"></i></a></li>';
	else
        echo '<li><a href="'.get_pagenum_link($max_page).'" title="Último"><i class="icon-double-angle-right"></i></a></li>';

	echo '</ul>'.$after."";
}


//attach our function to the wp_pagenavi filter
add_filter( 'wp_pagenavi', 'bootstrap_pagination', 10, 2 );
  
  
function bootstrap_pagination($html) {
    $out = '';
  
    //wrap a's and span's in li's
    $out = str_replace("<div","",$html);
    $out = str_replace("class='wp-pagenavi'>","",$out);
    $out = str_replace("<a","<li><a",$out);
    $out = str_replace("</a>","</a></li>",$out);
    $out = str_replace("<span","<li><span",$out);  
    $out = str_replace("</span>","</span></li>",$out);
    $out = str_replace("</div>","",$out);
  
    return '<ul class="pagination pagination-centered">'.$out.'</ul>';
}

function my_comment_form_args($user_identity, $post_id, $req) {
	$args = array(
		'comment_notes_after' => ''
	);
	return $args;
}


?>